package com.redtrusssoftware.truckloaderpro;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CustomAdapter extends BaseAdapter{

	private static ArrayList<Event> eventlist;
	
	private LayoutInflater mInflater;
	
	public CustomAdapter(Context context, ArrayList<Event> events){
		eventlist = events;
		mInflater = LayoutInflater.from(context);
	}
	
	public int getCount(){
		return eventlist.size();
	}

	@Override
	public Object getItem(int position) {
		return eventlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			   convertView = mInflater.inflate(R.layout.customrow, null);
			   holder = new ViewHolder();
			   holder.name = (TextView) convertView.findViewById(R.id.name);
			   holder.date = (TextView) convertView.findViewById(R.id.date);

			   convertView.setTag(holder);
			  } else {
			   holder = (ViewHolder) convertView.getTag();
			  }
			  
			  holder.name.setText(eventlist.get(position).getName());
			  holder.date.setText(eventlist.get(position).getDate());

			  return convertView;
	}

	
	static class ViewHolder {
		  TextView name;
		  TextView date;
		  ;
		 }
}
